unit uFrmConsultaTodos;

interface

uses
  Windows, IB_Components, Grids, IB_Grid, StdCtrls,
  IB_IncSearch, Controls, ExtCtrls, Classes, Graphics, SysUtils, Math, Dialogs,
  JvBaseDlg, JvProgressDialog, uFrmBaseModal;

type
  TConsultaTodos = class(TFrmBaseModal)
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Pesquisa: TIB_IncSearch;
    DSProcura: TIB_DataSource;
    Panel2: TPanel;
    Grid: TIB_Grid;
    procedure FormShow(Sender: TObject);
    procedure GridGetCellProps(Sender: TObject; ACol, ARow: Integer;
      AState: TGridDrawState; var AColor: TColor; AFont: TFont);
    procedure GridDblClick(Sender: TObject);
    procedure GridKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  ConsultaTodos: TConsultaTodos;

implementation

{$R *.dfm}

procedure TConsultaTodos.FormShow(Sender: TObject);
Var _Largura, x, Max, _Posicao : Integer;
    _Campos : TStringList;
    _Texto : String;
begin
  Pesquisa.SetFocus;
  _Largura := 0;
  _Campos := TStringList.Create;
  _Campos.Text := DSProcura.Dataset.FieldsDisplayWidth.Text;
  Max := _Campos.Count-1;
  for x := 0 to Max do begin
    _Texto := _Campos[x];
    _Posicao := Pos('=',_Texto);
    if _Posicao > -1 then begin
      _Largura := _Largura + StrToInt( Copy(_Texto,_Posicao+1,Length(_Texto)) );
    end;
  end;
  _Campos.Free;
  if _Largura < 376 then
    Width := 376
  else
  if _Largura <> 390 then
    Width := _Largura + 15 + 33;

  Pesquisa.Clear;
  inherited;
end;

procedure TConsultaTodos.GridGetCellProps(Sender: TObject; ACol,
  ARow: Integer; AState: TGridDrawState; var AColor: TColor; AFont: TFont);
begin
  inherited;
  if (aRow > 0) and (aCol > 0) then
     if not (gdSelected in AState) then
        if not Odd (aRow) then aColor := $00FFE1C4;
end;

procedure TConsultaTodos.GridDblClick(Sender: TObject);
begin
  inherited;
  ModalResult := mrOk;
end;

procedure TConsultaTodos.GridKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  inherited;
  if Key = VK_return then begin
    Key := 0;
    ModalResult := mrOk;
  end;
  if Key = VK_Escape then begin
    Key := 0;
    Pesquisa.Clear;
    Pesquisa.SetFocus;
  end;
end;

procedure TConsultaTodos.FormCreate(Sender: TObject);
begin
  inherited;
  (*SIMULA O PRESSIONAMENTO DA TECLA "ESC"*)
  keybd_event(VK_ESCAPE, 0, KEYEVENTF_EXTENDEDKEY, 0);
  keybd_event(VK_ESCAPE, 0, KEYEVENTF_KEYUP, 0);      
end;

end.
